package json.schema.demo;

import com.fasterxml.jackson.databind.JsonNode;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


@Controller
public class JsonSchemaController {

    @PostMapping("/validate/json/schema/")
    public Map<String, Object> validateJsonSchema(@RequestParam("json") String json,@RequestParam("schema") String schema) {
        JsonNode jsonNode = JsonSchemaValidator.getJsonNodeFromString(json);
        JsonNode schemaNode = JsonSchemaValidator.getJsonNodeFromFile(schema);
        return JsonSchemaValidator.validateJsonByFgeByJsonNode(jsonNode, schemaNode);
    }

}